package com.xinqi.modules.prepare.courseware.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareCoursewareData;
import com.xinqi.modules.prepare.courseware.domain.PrepareCoursewarePartEntity;
import com.xinqi.modules.prepare.courseware.dto.req.PrepareCoursewarePartCreateDTO;
import com.xinqi.modules.prepare.courseware.dto.req.PrepareCoursewarePartUpdateDTO;
import com.xinqi.modules.prepare.courseware.dto.rsp.PrepareCoursewarePartResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区互动课件切片转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareCoursewarePartConvert {
    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFile()))")
    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    public abstract PrepareCoursewarePartEntity create(PrepareCoursewarePartCreateDTO s);

    public abstract PrepareCoursewarePartCreateDTO create(PrepareCoursewareData.PrepareCoursewarePartData data);

    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFile()))")
    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    public abstract PrepareCoursewarePartEntity update(PrepareCoursewarePartUpdateDTO s, @MappingTarget PrepareCoursewarePartEntity t);

    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFile()))")
    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    public abstract PrepareCoursewarePartEntity update(PrepareCoursewarePartUpdateDTO s);

    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.parse(s.getFile(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    @Mapping(target = "questionContent", expression = "java(s.getQuestionContent()!=null?com.xinqi.common.base.utils.json.JSON.parseList(s.getQuestionContent(), com.xinqi.common.base.dto.QuestionBaseDTO.class):java.util.Collections.emptyList())")
    public abstract PrepareCoursewarePartResultDTO convert(PrepareCoursewarePartEntity s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    public abstract PrepareCoursewarePartEntity copy(PrepareCoursewarePartEntity t, @MappingTarget PrepareCoursewarePartEntity s);
}
